package  
{
	import qnx.ui.buttons.BackButton;
	import qnx.ui.buttons.Button;
	import qnx.ui.buttons.CheckBox;
	import qnx.ui.buttons.IconButton;
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.buttons.LabelPlacement;
	import qnx.ui.buttons.RadioButton;
	import qnx.ui.buttons.ToggleSwitch;
	import qnx.ui.display.TilingBackground;
	import qnx.ui.skins.SkinStates;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	/**
	 * @author juliandolce
	 */
	public class ButtonContainer extends BaseView 
	{
		
		private var updateFormatBtn:LabelButton;
		
		public function ButtonContainer()
		{
		}
		
		
		override protected function onAdded():void
		{
			configUI();
		}
		
		private function configUI():void
		{
			
			
			var bg:TilingBackground = new TilingBackground();
			addChild(bg);
			var bitmap:BitmapData = new BitmapData(100,100,false,0x333333);
			bg.bitmapData = bitmap;
			bg.setSize(1024,600);
			
			
			
			var label1:TextField = createLabel();
			label1.text = "qnx.ui.buttons.Button";
			addChild( label1 );
			
			var btn:Button = new Button();
			addChild( btn );
			btn.y = label1.y + label1.height + 10;
			btn.width = 100;
			
			//LabelButton
			var label2:TextField = createLabel();
			label2.text = "qnx.ui.buttons.LabelButton";
			addChild( label2 );
			label2.y = btn.y + btn.height + 10;
			
			updateFormatBtn = new LabelButton();
			updateFormatBtn.label = "open";
			updateFormatBtn.addEventListener( MouseEvent.CLICK, openFile );
			addChild( updateFormatBtn );
			updateFormatBtn.width = 100;
			updateFormatBtn.y = label2.y + label2.height + 10;
			
			var togglebtn:LabelButton = new LabelButton();
			togglebtn.label = "Toggle";
			addChild( togglebtn );
			togglebtn.y = updateFormatBtn.y;
			togglebtn.x = updateFormatBtn.width + 10 + updateFormatBtn.x;
			togglebtn.toggle = true;
			togglebtn.width = 100;
			togglebtn.addEventListener( MouseEvent.CLICK, changeTextFormat );
			
			var disablebtn:LabelButton = new LabelButton();
			addChild( disablebtn );
			disablebtn.label = "Diabled";
			disablebtn.enabled = false;
			
			disablebtn.width = 100;
			disablebtn.y = togglebtn.y;
			disablebtn.x = togglebtn.width + 10 + togglebtn.x;
			
			
			//CheckBox
			var label3:TextField = createLabel();
			label3.text = "qnx.ui.buttons.CheckBox";
			addChild( label3 );
			label3.y = disablebtn.y + disablebtn.height + 10;
			
			var cb:CheckBox = new CheckBox();
			addChild( cb );
			cb.label ="Select";
			cb.width = 150;
			cb.y = label3.y + label3.height + 10;
			cb.labelPlacement = LabelPlacement.RIGHT;
			
			
			
			//RadioButton
			var label4:TextField = createLabel();
			label4.text = "qnx.ui.buttons.RadioButton";
			addChild( label4 );
			label4.y = cb.y + cb.height + 10;
			
			var rb1:RadioButton = new RadioButton();
			rb1.label = "rb1";
			addChild( rb1 );
			rb1.y = label4.y + label4.height + 10;
			
			var rb2:RadioButton = new RadioButton();
			rb2.label = "rb2";
			addChild( rb2 );
			rb2.y = label4.y + label4.height + 10;
			rb2.x = rb1.width + 10 + rb1.x;
			
			var rb3:RadioButton = new RadioButton();
			rb3.label = "rb3";
			addChild( rb3 );
			rb3.y = label4.y + label4.height + 10;
			rb3.x = rb2.width + 10 + rb2.x;
			
			rb3.selected = true;
			

			
			

			

		}
		
		private function openFile( event:MouseEvent ) : void
		{
			//QNXApplication.qnxApplication.openFile("/mlc/media/drive/cameraroll/IMG_2.jpg");
		}
		
		private function handleToggleSelect(e:Event):void
		{
			trace("toggle selected?" + ToggleSwitch( e.target ).selected);
		}
		
		private function changeTextFormat(event:MouseEvent):void 
		{
			var format:TextFormat = new TextFormat();
			format.size = 16;
			format.font = "Arial";
			format.bold = true;
			format.color = 0xFF0000;
			format.align = TextFormatAlign.CENTER;
			
			updateFormatBtn.setTextFormatForState(format, SkinStates.DOWN );
		}
		
		private function showSettings(event:MouseEvent):void 
		{
			//var settings:SettingsView = new SettingsView();
			//addChild( settings );
		}
		
		private function createLabel():TextField
		{
			var txt:TextField = new TextField();
			
			var format:TextFormat = new TextFormat();
			format.font = "Arial";
			//format.bold = true;
			format.size = 16;
			format.color = 0xFFFFFF;
			txt.selectable = false;
			
			
			txt.defaultTextFormat = format;
			
			txt.autoSize = TextFieldAutoSize.LEFT;
			//txt.width = 300;
			
			return( txt );
		}
	}	
}